﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QLNS.Models
{
    public class DaoTaoModels
    {
        public static List<DaoTao> GetDSQuaTrinhDaoTao()
        {

            //khoi tao db
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();

            var query = from dt in context.DSQTDaoTao
                       // where dt.IDCanBo == id
                        select dt;
            return query.ToList<DaoTao>();
        }
        public static List<DaoTao> GetQuaTrinhDaoTaoTheoCanBo(int id)
        {

            //khoi tao db
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();

            var query = from dt in context.DSQTDaoTao
                        where dt.IDCanBo == id
                        select dt;
            return query.ToList<DaoTao>();
        }

       

        public static DaoTao GetChiTietQuaTrinhDaoTao(int id)
        {
            //khoi tao db
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = (from s in context.DSQTDaoTao
                         where s.ID == id
                         select s).FirstOrDefault();
            return query;

        }



        public static void Add(DaoTao qhgd)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            context.DSQTDaoTao.AddObject(qhgd);
            context.SaveChanges();
        }
        public static void Delete(int id)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = (from h in context.DSQTDaoTao
                         where h.ID == id
                         select h).FirstOrDefault();

            context.DSQTDaoTao.DeleteObject(query);
            context.SaveChanges();

        }
        public static void DeleteAllOfPerson(int id)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = from h in context.DSQTDaoTao
                        where h.IDCanBo == id
                        select h;
            foreach (var item in query)
            {
                context.DSQTDaoTao.DeleteObject(item);
            }
            context.SaveChanges();
        }
        //sua dan toc
        public static void Update(DaoTao id)
        {
            ITAPMNS2013Entities context = new ITAPMNS2013Entities();
            var query = from h in context.DSQTDaoTao
                        where h.ID == id.ID
                        select h;
            DaoTao kq = query.First<DaoTao>();
            kq = id;
            context.DSQTDaoTao.ApplyCurrentValues(kq);
            context.SaveChanges();

        }
    }
}